<template>
	<view style="width: 100vw;position: relative;">

		<!-- <status-bar></status-bar> -->
		<myLoading v-if="isLoading"></myLoading>
		<template v-else>

			<image  style="width: 100%;margin-top: -30rpx;" src="../../static/12.jpg" mode="widthFix"></image>

			


			<!-- 余额  103-->
			<view
				style="position: absolute;left:103rpx;top: 294rpx;width: 115rpx;height: 75rpx;background-color: #fd873b;display: flex;align-items: center;justify-content: center;">
				<view style="display: flex;align-items: center;font-size: 73rpx;font-weight: 700;color: #fff;">
					{{ changeInt }}</view>
				<view style="display: flex;align-items: flex-end;font-size: 53rpx;font-weight: 700;margin-top: 10rpx;color: #fff;">.{{changeDec}}</view>
			</view>



			<!-- 余额   #fe8b40  146下-->
			<view
				style="position: absolute;left:146rpx;top: 388rpx;width: 52rpx;height: 35rpx;background-color:fe8b40;display: flex;align-items: center;justify-content: center;">
				<view style="display: flex;align-items: center;font-size: 27rpx;color: #fff;">
					{{ changeInt }}</view>
				<view style="display: flex;align-items: center;font-size: 27rpx;color: #fff;">.{{changeDec}}</view>
			</view>


			<view @click="goBack" style="width: 200rpx;height: 155rpx;position: absolute;left: 0;top: 0;"></view>

		</template>
	</view>
</template>

<script>

import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue'
export default {
	components: {
		uniIcons
	},
	data() {
		return {
			isLoading: true,
			isone:true,
			formData: {
				name: '',
				phone: '',
				idCard: '',
				firstReceiveDate: '',
				avatar: ''
			},
			// 零钱相关变量
			change: 0,
			changeInt: 0,
			changeDec: 0,
		}
	},
	onShow() {
		// 页面加载时，尝试从本地缓存获取数据
		this.loadUserData();
	},
	onLoad() {
		// 定义一个0.3-1的随机数
		let randomNum = Math.random() * 0.7 + 0.3;
		// 转换为毫秒
		let randomDelay = randomNum * 1000;
		// 延迟执行
		setTimeout(() => {
			setTimeout(() => {
				this.isLoading = false
			}, randomDelay)
		})
	},
	methods: {
		goMy() {
			uni.navigateTo({
				url: '/pages/my/my'
			})
		},
		loadUserData() {
				const userData = uni.getStorageSync('userInfo');
				console.log(':', userData);
				if (userData) {
					const parsedData = JSON.parse(userData);
					console.log('成功加载本地存储的数据:', parsedData);
					this.formData = parsedData;
					console.log('成功加载本地存储的数据:', this.formData);
					
					// 处理零钱分割
					this.processChangeAmount(parsedData);
				}
		},
		
		// 处理零钱金额分割
		processChangeAmount(data) {
			const change = parseFloat(data.change) || 0;
			this.change = change;
			
			// 分割整数部分和小数部分
			this.changeInt = Math.floor(change);
			
			// 处理小数部分，确保两位数格式
			const decimal = Math.round((change - this.changeInt) * 100);
			this.changeDec = decimal.toString().padStart(2, '0');
			
			console.log('处理后的零钱:', {
				original: this.change,
				int: this.changeInt,
				dec: this.changeDec
			});
		},
		
		goBack() {
			uni.navigateBack();
		},
	}
}

</script>

<style lang="scss" scoped></style>
